#	$Id: Makefile 1069 2010-04-26 02:36:16Z phrakt $
#
# Makefile for mod_java
#
#
# This build file is somewhat more complicated than your ordinary module
# Makefile, mostly because we have to build Java code and corresponding JNI
# bindings for the Java API.
#
#
# Targets:
# --------
#
#    javalib:	builds the JAR library file
#
#    jnihdr:	generates C headers from the Java source for JNI bindings
#
#    javadoc:	generates Javadoc in HTML format from the Java source
#
#

.include "../../share/mk/own.mk"


MOD_NAME=	mod_java
MOD_VERSION=	0.1
MOD_AUTHOR=	Jean-Francois Brousseau <phrakt@gmail.com>
MOD_DESC=	embedded Java Virtual Machine that allows modules to be \
		written in the Java language

SRCS=		mod_java.c						\
		ca_terraquati_canopy_Canopy.c				\
		ca_terraquati_canopy_http_impl_HTTPSocketImpl.c		\
		HTTPMessage.c


MODJAR=		${MOD}-api-${VERSION_MAJOR}.${VERSION_MINOR}.jar

CFLAGS+=	-I${JAVA_INCDIR} -I${JAVA_MD_INCDIR}
LDFLAGS+=	-L/usr/lib -L${JAVA_LIBDIR} -ljvm

CLEANFILES+=	${JAVA_OBJS} ${MODJAR} ${JAVA_OBJDIR} ${JAVA_DOCDIR}

#
# Java parameters
#

JAVA_HOME=	/usr/local/jdk1.5.0
JAVA_TOOL=	${JAVA_HOME}/bin/java
JAVAC_TOOL=	${JAVA_HOME}/bin/javac
JAVAH_TOOL=	${JAVA_HOME}/bin/javah
JAVADOC_TOOL=	${JAVA_HOME}/bin/javadoc
JAR_TOOL=	jar

JAVAH_HDR=	ca_terraquati_canopy.h

JAVADOC_DESTDIR=${DOCDIR}/mod_java


JAVA_INCDIR=	${JAVA_HOME}/include
JAVA_LIBDIR=	${JAVA_HOME}/jre/lib/${MACHINE_ARCH}/server

JAVA_MD_INCDIR=	${JAVA_INCDIR}/${OS:L}


JAVA_SRCDIR=	${.CURDIR}/javasrc
JAVA_OBJDIR=	${.CURDIR}/build
JAVA_DOCDIR=	${.CURDIR}/javadoc
JAVA_SRCS!=	find ${JAVA_SRCDIR} -name '*.java' | sed -e 's/\n/ /g'
JAVA_OBJS=	${JAVA_SRCS:.java=.class}

JAVA_CLASSES=	${JAVA_SRCS:C/${JAVA_SRCDIR}\///:C/\//./g:.java=}

JAVA_CLASSPATH=	${JAVA_SRCDIR}:${JAVA_OBJDIR}


all: javalib jnihdr module javadoc


jnihdr:
	${JAVAH_TOOL} -jni -classpath ${JAVA_CLASSPATH}			\
	    -o ${JAVAH_HDR} ${JAVA_CLASSES}


javalib:
	@if [ ! -e ${JAVA_OBJDIR} ]; then				\
		${MKDIR} ${JAVA_OBJDIR};				\
	fi
	${JAVAC_TOOL} -classpath ${JAVA_CLASSPATH} -d ${JAVA_OBJDIR}	\
	    ${JAVA_SRCS}
	${JAR_TOOL} cf ${MODJAR} -C build .

javadoc:
	${JAVADOC_TOOL} -d ${JAVA_DOCDIR} ${JAVA_SRCS}


install: beforeinstall
	${INSTALL} -o ${MODOWN} -g ${MODGRP} -m ${MODMODE} \
            ${MODFILE} ${DESTDIR}${MODDIR}/${MODFILE}
	${INSTALL} -o ${MODOWN} -g ${MODGRP} -m ${MODMODE} \
            ${MODJAR} ${DESTDIR}${MODDIR}/${MODJAR}


.include "../../share/mk/mod.mk"
